﻿
$(function () {
    if (getLogin_State() == 1) {
        GetUser_Info();
        $("#per_info_Save").click(function () { save_info(); });
    } else { window.location.href = "m_login.html"; }

})
function GetUser_Info()//用户信息
{
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "106" },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                $("#my_data_imgurl").attr("src", data.img);
                $("#my_data_name").html(data.name);
                $("#my_data_point").html(data.point);
            }
        }
    });
}


function getLogin_State() {
    var ss_login = 0;
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "101" },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                ss_login = 1;
            }
        }
    });
    return ss_login;
}

var usercount = 1;
//获取项目列表
function getUsers(index) {
    if (index <= usercount) {
        var proid = $.query.get("proid");
        //var proTitle = $("#pro_cate");
        switch (proid) {
            case -1: $("#pro_cate_" + proid).css("color", "#47A6F8"); break;
            case 0: $("#pro_cate_" + proid).css("color", "#47A6F8"); break;
            case 1: $("#pro_cate_" + proid).css("color", "#47A6F8"); break;
        }

        $.ajax({
            type: "post", url: "/app/get_zs_web.ashx",
            data: { "por": "123", "pageIndex": index, "cateid": proid },
            async: false, dataType: "json", success: function (data) {
                if (data.code == 1) {

                    usercount = data.count;
                    var item = ''; var comStr = ''; var item_url = '';
                    for (var i = 0; i < data.list.length; i++) {
                        item_url = "proDetails.html?proid=" + data.list[i].Guid;
                        switch (proid) {
                            case -1: comStr = "<a href=\"m_proUser.html?proid=" + data.list[i].Guid + "\">申请人员</a>&nbsp;&nbsp;&nbsp;<a href=\"m_proAdd.html?proid=" + data.list[i].Guid + "\">编辑</a>"; break;//"<a href=\"proUserCom.html?proid=" + data.list[i].Guid + "\">我要评论</a>";
                            case 0: comStr = "<a href=\"javascript:void(0);\" id='item_cancel' onclick=\"GetItemCancel('" + data.list[i].Guid + "')\">取消关注</a>"; break;
                            case 1: break;//comStr = "<a href=\"proComment.html?proid=" + data.list[i].Guid + "\">我要评论</a>";
                        }
                        
                        item += "<div class=\"div_content\"><a href=\"m_proPage.html?proid=" + data.list[i].Guid + "\"><p class=\"p_title\"><span>" + data.list[i].Title + "</span></p></a><ul class=\"ul_list\"><li><span>项目预算：</span><span>" + data.list[i].ItemBbudget + "元</span></li><li><span>已申请：</span><span>" + data.list[i].ApplyCount + "人</span></li><li><span>项目人数：</span><span>" + data.list[i].ItemCount + "人</span></li><li><span>项目周期：</span><span>" + data.list[i].ItemCycle + "天</span></li> <li><span>人员要求：</span><span>" + data.list[i].ItemRequire + "</span></li></ul><p class=\"p_btn\">" + comStr + "</p></div>";
                        $("#m_indexCount").val(usercount);



                    }
 
                    $("#item_list").append(item);  //项目  
                }
            }
        });
    }

}



//获取订单列表
function get_pro_order(index) {
    if (index <= usercount) {
 
        //var proid = $.query.get("proid");
        //var proTitle = $("#pro_cate");
        //switch (proid) {
        //    case -1: proTitle.text("我发布的项目"); break;
        //    case 0: proTitle.text("我关注的项目"); break;
        //    case 1: proTitle.text("我参与的项目"); break;  
        //}

        $.ajax({
            type: "post", url: "/app/get_zs_web.ashx",
            data: { "por": "165", "pageIndex": index},
            async: false, dataType: "json", success: function (data) {
                if (data.code == 1) {

                    usercount = data.count;
                    var item = ''; var comStr = ''; var item_url = '';
                    for (var i = 0; i < data.list.length; i++) {
                        var adrStr = '';
                        if (data.list[i].ProRemark.length > 0)
                        {
                            var adrPart = new Array()
                           
                            adrPart = data.list[i].ProRemark.split(";");
                            adrStr = "<li><span>" + adrPart[0] + "</span></li><li><span>" + adrPart[1] + "</span></li><li><span>" + adrPart[1] + "</span></li>";
                        }
                        item += "<div class=\"div_content\"><p class=\"p_title\"><span>" + data.list[i].ProBody + "</span></p><ul class=\"ul_list\"><li><span>金额：</span><span>" + (data.list[i].ProTotalFee / 100) + "元</span></li><li><span>时间：</span><span>" + data.list[i].TimeDate + "</span></li><li><span>订单号：</span><span>" + data.list[i].ProTradeNo + "</span></li>" + adrStr + "</ul></div>";
                        $("#m_indexCount").val(usercount);



                    }

                    $("#item_list").append(item);  //项目  
                }
            }
        });
    }

}

//基本资料
function save_info() {
    var nickname = $("#nickname").val();
    var email = $("#my_email").val();
    if (nickname.length > 0 && email.length > 0) {
        $.ajax({
            type: "post", url: "/app/get_zs_web.ashx",
            data: { "por": "130", "nickname": nickname, "email": email },
            async: false, dataType: "json", success: function (data) {
                if (data.code == 1) {
                    alert("保存成功");
                 window.location.href="m_perInfo.html";
                }
            }
        });
    } else { alert("请填完所有项"); }
}

//详细资料
function save_moreInfo() {
    var sex = $("#my_sex").val();
    var my_UIdCard = $("#my_UIdCard").val();
    var my_UTrueName = $("#my_UTrueName").val();
    var my_UBrithday = $("#my_UBrithday").val();
    var my_UMajor = $("#my_UMajor").val();
    var my_inCate = $("#my_inCate").val(); 
    var my_Desc = $("#my_Desc").val();
    var my_UTag = $("#my_UTag").val();

    var my_hometown = $("#my_hometown").val();
    var my_adr = $("#my_adr").val();
    var my_school = $("#my_school").val();
    var my_utel = $("#my_utel").val();
    var my_harvest = $("#my_harvest").val();
    var my_edu = $("#my_education").val();
    var my_UDepartment = $("#my_UDepartment").val();
    var my_wxName = $("#my_wxName").val();
    var my_wxIsAgree = $("#huoqu_toux").attr("checked");
    //收货地址
    var my_adrName = $("#my_adrName").val();
    var my_adrPhone = $("#my_adrPhone").val();
    var my_adrDetails = $("#my_adrDetails").val();


    if(my_wxIsAgree=="checked"){my_wxIsAgree=1;}else{my_wxIsAgree=0;}
    if (my_wxName.length > 0 && my_UDepartment.length > 0 && my_UBrithday.length > 0 && my_UTrueName.length > 0 && my_UMajor.length > 0 && my_inCate.length > 0 && my_adr.length > 0 && my_utel.length > 0 && my_adrName.length > 0 && my_adrPhone.length > 0 && my_adrDetails.length>0) {
        $.ajax({
            type: "post", url: "/app/get_zs_web.ashx",
            data: { "por": "131", "usex": sex, "uidCard": my_UIdCard, "brithStr": my_UBrithday, "uMajor": my_UMajor, "inCate": my_inCate, "descStr": my_Desc, "tagStr": my_UTag, "nickname": my_UTrueName, "uHometown": my_hometown, "adrStr": my_adr, "schoolStr": my_school, "phone": my_utel, "harvestStr": my_harvest, "educationStr": my_edu, "departmentStr": my_UDepartment, "wxNameStr": my_wxName, "wxAgreeStr": my_wxIsAgree, "adrName": my_adrName, "adrPhone": my_adrPhone, "adrDetails": my_adrDetails },
            async: false, dataType: "json", success: function (data) {
                if (data.code == 1) {
                    alert("保存成功");
                    if (data.proid.length>0) { window.location.href = "m_proPage.html?proid=" + proid; } else { window.history.go(-1); }

                 
                    //window.location.href = "m_perInfo.html";
                }
            }
        });
   } else { alert("请填完必填项"); }
}
//填充个人信息
function GetMyInfo() { 
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "132" },
        async: true, dataType: "json", success: function (data) {
            if (data.code == 1) {
                $("#my_pic_url").attr("src", data.info.ImgUrl);
                $("#my_phone").html(data.info.UPhone);
                $("#nickname").val(data.info.UNickName);
                $("#my_email").val(data.info.UEmail);
                if (data.info.UCate == 1 || data.info.UCate == -1) {
                  
                    $("#my_more_info").show();
                    $("#my_UIdCard").val(data.moreInfo.UIdCard);
                    $("#my_UTrueName").val(data.moreInfo.UTrueName);
                    $("#my_UBrithday").val(GetFormatDate(data.moreInfo.UBrithday));
                    $("#my_UMajor").val(data.moreInfo.UMajor);
                    $("#my_inCate").val(data.moreInfo.UIndustry);
                    $("#my_Desc").val(data.moreInfo.Descriptions);
                    $(" #my_UTag").val(data.moreInfo.UTag);

                    $("#my_hometown").val(data.moreInfo.USchool);
                    $("#my_adr").val(data.moreInfo.UAdrr);
                    $("#my_school").val(data.moreInfo.USchool);
                    $(" #my_utel").val(data.moreInfo.UTel);
                    $(" #my_harvest").val(data.moreInfo.UHarvest);
                    $("#my_sex").val(data.moreInfo.USex);
                    $("#my_education").val(data.moreInfo.UEducation);
                    $("#my_UDepartment").val(data.moreInfo.UDepartment);
                    $("#my_wxName").val(data.moreInfo.Weixin);
                    $("#my_adrName").val(data.moreInfo.UAdrName);
                    $("#my_adrPhone").val(data.moreInfo.UAdrPhone);
                    $("#my_adrDetails").val(data.moreInfo.UAdrDetails);

                } else if (data.info.UCate == 2) {
                    $("#com_more_info").show();
                    $("#com_UserName").val(data.moreInfo.UTrueName)
                    $("#com_email").val(data.moreInfo.UEmail);
                    $("#com_tel").val(data.moreInfo.UTel);
                    $("#com_name").val(data.moreInfo.UComName);
                    $("#com_place").val(data.moreInfo.UComPlace);
                    $("#com_inCate").val(data.moreInfo.UIndustry);
                    $("#com_nature").val(data.moreInfo.UComNature);
                }

            }
        }
    });
}
//公司详细资料
function com_moreInfo() {
    var com_UserName = $("#com_UserName").val();
    var com_email = $("#com_email").val();
    var com_tel = $("#com_tel").val();
    var com_name = $("#com_name").val();
    var com_place = $("#com_place").val();
    var com_inCate = $("#com_inCate").val();
    var com_nature = $("#com_nature").val();
    if (com_UserName.length > 0 && com_email.length > 0 && com_tel.length > 0 && com_name.length > 0 && com_place.length > 0 && com_inCate.length > 0 && com_nature.length > 0) {
        $.ajax({
            type: "post", url: "/app/get_zs_web.ashx",
            data: { "por": "134", "userStr": com_UserName, "email": com_email, "comtel": com_tel, "comname": com_name, "comadr": com_place, "inCate": com_inCate, "comNature": com_nature },
            async: false, dataType: "json", success: function (data) {
                if (data.code == 1) {
                    window.location.href = "m_perInfo.html";
                }
            }
        });
    } else { alert("请填完所有项"); }
}
//分类获取
function GetCateData() {
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": 110 },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                var con = ' <option value="">请选择...</option>';
                for (var i = 0; i < data.list.length; i++) {
                    con += "  <option value='" + data.list[i].ID + "'>" + data.list[i].ClassName + "</option> ";
                }
                $("#com_inCate,#my_inCate").html(con);

            } else { alert(data.msg); }
        }
    });
}
//日期格式转换
function GetFormatDate(date_str) {
    var date = new Date(date_str);
    var month = (date.getMonth() + 1);
    var day = date.getDate();
    if (month < 10) { month = "0" + month; }
    if (day < 10) { day = "0" + day; }
    var dStr = date.getFullYear() + "-" + month + "-" +day;
    return dStr;
}

//密码保存
function GetSave_Pwd() {
    var edit_pwd = $("#edit_pwd").val();
    var edit_new_pwd = $("#edit_new_pwd").val();
    var edit_new_pwd2 = $("#edit_new_pwd2").val();
    if (edit_pwd.length > 0 && edit_new_pwd.length > 0) {

        if (edit_new_pwd2 == edit_new_pwd) {
            $.ajax({
                type: "post", url: "/app/get_zs_web.ashx",
                data: { "por": "135", "pwd": edit_pwd, "newPwd": edit_new_pwd },
                async: false, dataType: "json", success: function (data) {
                    if (data.code == 1) {
                        alert("密码修改成功");
                        window.location.href = "/mob2/m_myProfile.html";
                    } else { alert(data.msg); }

                }
            });
        } else { alert("新密码两次输入不一致"); }
    } else { alert("请填完所有项"); }
}
function GetItemCancel(str) {
    $.ajax({
        type: "post", url: "/app/get_zs_web.ashx",
        data: { "por": "124", "proid": str },
        async: false, dataType: "json", success: function (data) {
            if (data.code == 1) {
                alert("取消成功");
                window.location.href = "m_myProject.html";
            } else { alert(data.msg); }
        }
    });
}

